package org.cuckoocs.tool.key;


/**
 * two positive int number convert to a unique positive int number. but ,both of the two num must less than 0b111111111111111(32767)
 * 
 * 32bit-->int
 * 2_15_15
 * 00_000000000000000_000000000000000
 * @author shuntao
 *
 */
public class I2ck {
	
	static final int _l15 = 0b00_000000000000000_111111111111111;
	static final int _r15 = 0b00_111111111111111_000000000000000;
	
	private static final int min = -0b11111111111111;
	private static final int max = 0b111111111111111;
	
	public static int ck(int k1, int k2){
		if (k1 < min || k1 > max || k2 < min || k2 > max) {
			return -1;
		}
		return k1 << 15 | k2;
	}
	
	public static int[] uck(int k){
		return new int[]{(k & _r15) >> 15, k & _l15};
	}
	
	public static int uckl(int k){
		return (k & _r15) >> 15;
	}
	
	public static int uckr(int k){
		return (k & _r15) >> 15;
	}
	
}
